package main

import (
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/elastic/bus"
	"github.com/streadway/amqp"
	"golang.org/x/net/context"
	"strconv"
)

//更新分店的状态到
func main() {

	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("queue.log.setShopStatus"))
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("queue.setShopStatus"), func(msg amqp.Delivery) {
		// 通过消息队列将分店基本信息添加/更新到ES

		shopId, err := strconv.Atoi(string(msg.Body))
		if err != nil {
			utils.Logerr.Printf("门店id转换成int失败，shopId:%s, err:%s", string(msg.Body), err)
		}
		utils.Logerr.Printf("更新分店的状态到Es,接受数据shopId=%d", shopId)

		rpcShop := new(bus.Shop).Init()
		defer rpcShop.Close()

		reply := false
		if err := rpcShop.SetShopStatus(context.Background(), &shopId, &reply); err != nil {
			utils.Logerr.Printf("更新分店的状态到Es错误,shopId=%d err：%s", shopId, err.Error())
		}

		utils.Logerr.Printf("更新分店的状态到Es处理完成 shopId=%d", shopId)
		return
	})
	if err != nil {
		utils.Logerr.Printf("更新分店的状态到EsES处理错误 err:%s", err.Error())
	}
}
